home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swags_z.zip / STRINGS.SWG / 0070_String Conversions.pas < prev    next >
Pascal/Delphi Source File  |  1994-01-27  |  4KB  |  104 lines

  1. {***********************************************************************}
  2. UNIT Strings;           {  String Conversion Routines,                  }
  3.                         {  Last Updated Dec 07/93                       }
  4.                         {  Copyright (C) 1993, Greg Estabrooks          }
  5.                         {  NOTE: Requires TP 6.0+ to compile.           }
  6. INTERFACE
  7. (************************************************************************)
  8. CONST
  9.      HexList :ARRAY[0..15] OF CHAR ='0123456789ABCDEF';
  10.  
  11. FUNCTION BHex( V :BYTE ) :STRING;
  12. FUNCTION WHex( V :WORD ) :STRING;
  13. FUNCTION LHex( Long :LONGINT ) :STRING;
  14. PROCEDURE UpperCase( VAR UpStr :STRING );
  15. PROCEDURE LowerCase( VAR LoStr :STRING );
  16.  
  17. IMPLEMENTATION
  18. (************************************************************************)
  19. FUNCTION HiWord( Long :LONGINT ) :WORD; ASSEMBLER;
  20.                       { Routine to return high word of a LongInt.       }
  21. ASM
  22.   Mov AX,Long.WORD[2]              { Move High word into AX.            }
  23. END;
  24.  
  25. FUNCTION LoWord( Long :LONGINT ) :WORD; ASSEMBLER;
  26.                       { Routine to return low word of a LongInt.        }
  27. ASM
  28.   Mov AX,Long.WORD[0]              { Move low word into AX.             }
  29. END;
  30.  
  31.  
  32. FUNCTION BHex( V :BYTE ) :STRING;
  33.                        { Routine to convert a byte to a Hex string.     }
  34. BEGIN
  35.   BHex := HexList[V Shr 4] + HexList[V Mod 16];
  36. END;
  37.  
  38. FUNCTION WHex( V :WORD ) :STRING;
  39.                        { Routine to convert a word to a Hex string.     }
  40. BEGIN
  41.   WHex := Bhex(Hi(V)) + BHex(Lo(V));
  42. END;
  43.  
  44. FUNCTION LHex( Long :LONGINT ) :STRING;
  45.                        { Routine to convert a longint to a Hex string.  }
  46. BEGIN
  47.   LHex := WHex(HiWord(Long))+WHex(LoWord(Long));
  48. END;
  49.  
  50. PROCEDURE UpperCase( VAR UpStr :STRING ); ASSEMBLER;
  51.                      {  Routine to convert string to uppercase          }
  52. ASM
  53.   Push ES                       {  Save Registers to be used            }
  54.   Push DI
  55.   Push CX
  56.   LES DI,UpStr                  {  Point ES:DI to string to be converted}
  57.   Sub CX,CX                     {  Clear CX                             }
  58.   Mov CL,ES:[DI]                {  Load Length of string for looping    }
  59.   Cmp CX,0                      {  Check for a clear string             }
  60.   JE @Exit                      {  If it was then exit                  }
  61. @ReadStr:
  62.   Inc DI                        {  Point to next Character              }
  63.   Cmp BYTE PTR ES:[DI],'z'      {  If Character above 'z' jump to end of}
  64.   Ja @LoopEnd                   {  loop.                                }
  65.   Cmp BYTE PTR ES:[DI],'a'      {  if below 'a' jump to end of loop.    }
  66.   Jb @LoopEnd
  67.   Sub BYTE PTR ES:[DI],32       {  If not make it upper case            }
  68. @LoopEnd:
  69.   Loop @ReadStr                 {  Loop Until done                      }
  70. @Exit:
  71.   Pop CX                        {  Restore registers                    }
  72.   Pop DI
  73.   Pop ES
  74. END;{UpperCase}
  75.  
  76. PROCEDURE LowerCase( VAR LoStr :STRING ); ASSEMBLER;
  77.                      {  Routine to convert a string to lower case       }
  78. ASM
  79.   Push ES                       {  Save Registers to be used            }
  80.   Push DI
  81.   Push CX
  82.   LES DI,LoStr                  {  Point ES:DI to string to be converted}
  83.   Sub CX,CX                     {  Clear CX                             }
  84.   Mov CL,ES:[DI]                {  Load Length of string for looping    }
  85.   Cmp CX,0                      {  Check for a clear string             }
  86.   JE @Exit                      {  If it was then exit                  }
  87. @ReadStr:
  88.   Inc DI                        {  Point to next Character              }
  89.   Cmp BYTE PTR ES:[DI],'Z'      {  If Character above 'Z' jump to end of}
  90.   Ja @LoopEnd                   {  loop.                                }
  91.   Cmp BYTE PTR ES:[DI],'A'      {  if below 'A' jump to end of loop.    }
  92.   Jb @LoopEnd
  93.   Add BYTE PTR ES:[DI],32       {  If not make it Lower case            }
  94. @LoopEnd:
  95.   Loop @ReadStr                 {  Loop Until done                      }
  96. @Exit:
  97.   Pop CX                        {  Restore registers                    }
  98.   Pop DI
  99.   Pop ES
  100. END;{LowerCase}
  101.  
  102. BEGIN
  103. END.
  104. {***********************************************************************}